package com.etnet.streamserver.view.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;

public class CharsetEncodingFilter implements Filter {
    private static Logger log = Logger.getLogger(CharsetEncodingFilter.class.getName());
    String encoding;

    public void destroy() {
    }

    public void doFilter(ServletRequest prequest, ServletResponse response, FilterChain chain) throws IOException,
            ServletException {
        HttpServletRequest request = (HttpServletRequest) prequest;
        request.setCharacterEncoding(this.encoding);
        response.setCharacterEncoding(this.encoding);

        chain.doFilter(request, response);
    }

    public void init(FilterConfig fConfig) throws ServletException {
        this.encoding = fConfig.getInitParameter("encoding");
    }
}